package com.project.dao.impl;

import java.sql.SQLException;
import java.util.UUID;

import com.project.common.util.QueryUtils;
import com.project.dao.OrginDao;
import com.project.dao.bean.Organization;

/**
 * 后台 组织注册 Dao Impl
 * @author Sn
 *
 */
public class OrginDaoImpl extends BaseDaoImpl implements OrginDao 
{

	// 机构信息添加方法
	public void save(Organization orgin) throws SQLException 
	{
		// 使用UUID作为主键
		UUID uuid = UUID.randomUUID();
		orgin.setOrg_id(uuid.toString());
		this.getSqlMapClient().insert("saveorgin", orgin);
	}

	// 机构信息删除方法
	public void delete(String id) throws Exception 
	{
		this.getSqlMapClient().delete("deleteorgin", id);
	}

	// 根据传入的id返回对应机构的信息的方法
	public Organization findbyid(String id) 
	{
		Organization orgin = null;
		try 
		{
			orgin = (Organization) this.getSqlMapClient().queryForObject("findbyid", id);
			
		} catch (SQLException e) 
		{
			e.printStackTrace();
		}
		return orgin;
	}

	// 更新机构信息方法
	public void updateorgin(Organization orgin) 
	{
		try 
		{
			this.getSqlMapClient().update("updateorgin", orgin);
		} catch (SQLException e) 
		{
			e.printStackTrace();
		}

	}

	// 带分页的显示方法
	public QueryUtils listorgin(QueryUtils page) 
	{
		try 
		{
			// 分页之前，先求出总的的数据条数
			Long count = Long.parseLong(this.getSqlMapClient().queryForObject("countorgin").toString());
			page.setPagetotal(count);
			
		} catch (NumberFormatException e1) 
		{
			e1.printStackTrace();
			
		} catch (SQLException e) 
		{
			e.printStackTrace();
		}
		try 
		{
			//得到当前页的数据信息
			page.setPagelist(this.getSqlMapClient().queryForList("listorgin",page));
		} catch (SQLException e) 
		{
			e.printStackTrace();
		}

		return page;
	}

}
